<?php

namespace app\service;

use app\exception\ErrnoPlus;
use app\model\LanguageTypeModel;
use share\exception\ApiException;
use share\service\BaseModelService;
use share\utils\Helper;

class LanguageTypeService extends BaseModelService
{
    public static function getModel()
    {
        return new LanguageTypeModel();
    }


    public static function addLanguage($param){ 
        $item  = Helper::arrayCamelKeyToUnderscore($param);
        self::add($item);
    }

    public static function updateLanguage($param){        
        $id =  $param['language'];
        unset($param['language']);
        $origin = self::getBase($id);        
        if(empty($origin)){
            throw new ApiException("origin data is not exist",ErrnoPlus::COMMON_ERROR);
        }
        $item = Helper::arrayCamelKeyToUnderscore($param);
        $update = [];
        foreach($item as $key => $val){
            if($val != $origin[$key]){
                $update[$key] = $val;
            }
        }
        if(count($update) > 0){
            self::update($id,$update);
        }
    }

    public static function delLanguage($id){
        self::del($id);
    }

    public static function buildCondition($filter)
    {
        return [];
    }
}
